 

package com.zdkj.subway.rca.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import com.zdkj.common.core.exceltools.MultipartFileToFile;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;

import com.zdkj.common.security.util.ObjectUtils;


import com.zdkj.subway.rca.entity.SwCkBackElectronicBillCcbTmp;
import com.zdkj.subway.rca.service.SwCkBackElectronicBillCcbTmpService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;


/**
 * 建设银行电子账单临时表
 *
 * @author stw
 * @date 2020-09-27 11:58:59
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swckbackelectronicbillccbtmp" )
@Api(value = "swckbackelectronicbillccbtmp", tags = "银行票据单管理-银行电子账单-建设银行电子账单临时表管理")
public class SwCkBackElectronicBillCcbTmpController {

    private final SwCkBackElectronicBillCcbTmpService swCkBackElectronicBillCcbTmpService;

    /**
     * 导入建设银行电子账单
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "导入建设银行电子账单", notes = "导入建设银行电子账单")
    @SysLog("导入建设银行电子账单")
    @PostMapping({ "/saveBatch" })
    @PreAuthorize("@pms.hasPermission('sw_ck_back_electronic_bill_ccb_tmp_import')")
    public R saveBatch(@RequestParam("file") final MultipartFile file) throws Exception {
        final File excelFile = MultipartFileToFile.multipartFileToFile(file);
        return R.ok((Object)this.swCkBackElectronicBillCcbTmpService.saveBatchWithExcel(excelFile));
    }

    /**
     * 建设银行导入预处理查询
     * @return
     */
    @ApiOperation(value = "建设银行导入预处理查询", notes = "建设银行导入预处理查询")
    @GetMapping("/list" )
    @PreAuthorize("@pms.hasPermission('sw_ck_back_electronic_bill_ccb_tmp_import')")
    public R getSwCkBackElectronicBillCcbTmpList() {
        SwCkBackElectronicBillCcbTmp swCkBackElectronicBillCcbTmp = new SwCkBackElectronicBillCcbTmp();
        final SwCkBackElectronicBillCcbTmp obj =  ObjectUtils.getDefaultObj(SwCkBackElectronicBillCcbTmp.class);
        swCkBackElectronicBillCcbTmp.setCreatorId(obj.getCreatorId());
        return R.ok(swCkBackElectronicBillCcbTmpService.list(Wrappers.query(swCkBackElectronicBillCcbTmp)));
    }
    /**
     * 建设银行导入预处理确认
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "建设银行导入预处理确认", notes = "建设银行导入预处理确认")
    //@SysLog("建设银行导入预处理确认")
    @PostMapping({ "/saveBatchOk" })
    //@PreAuthorize("@pms.hasPermission('sw_ck_back_electronic_bill_ccb_tmp_import')")
    public R saveBatchOk() throws Exception {
        final SwCkBackElectronicBillCcbTmp obj =  ObjectUtils.getDefaultObj(SwCkBackElectronicBillCcbTmp.class);
        this.swCkBackElectronicBillCcbTmpService.saveBatchWithExcelOk(obj.getCreatorId());
        return R.ok(true);
    }
    /**
     * 建设银行导入预处理取消
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "建设银行导入预处理取消", notes = "建设银行导入预处理取消")
    @SysLog("建设银行导入预处理取消")
    @PostMapping({ "/saveBatchCancel" })
    @PreAuthorize("@pms.hasPermission('sw_ck_back_electronic_bill_ccb_tmp_import')")
    public R saveBatchCancel() throws Exception {
        final SwCkBackElectronicBillCcbTmp obj =  ObjectUtils.getDefaultObj(SwCkBackElectronicBillCcbTmp.class);
        this.swCkBackElectronicBillCcbTmpService.saveBatchWithExcelCancel(obj.getCreatorId());
        return R.ok(true);
    }


    /**
     * 导出模板
     * @param
     * @return
     * @throws
     */
    @ApiOperation(value = "导出模板", notes = "导出模板")
    @GetMapping("/exportTamplate")
    public void exportTamplate(HttpServletResponse response) {
        swCkBackElectronicBillCcbTmpService.exportTamplates(response);
    }
}
